///*------------------------------------------------------------------------
//|                            FILE DESCRIPTION                            |
//------------------------------------------------------------------------*/
///*------------------------------------------------------------------------
//|  - File name     : os_task.h
//|  - Author        : zeweni
//|  - Update date   : 2021.03.25
//|  - Copyright(C)  : 2021-2021 zeweni. All rights reserved.
//------------------------------------------------------------------------*/
///*------------------------------------------------------------------------
//|                            COPYRIGHT NOTICE                            |
//------------------------------------------------------------------------*/
///*
// * Copyright (C) 2021, zeweni (17870070675@163.com)

// * This file is part of Ant Real Time Operating System.

// * Ant Real Time Operating System is free software: you can redistribute 
// * it and/or modify it under the terms of the Apache-2.0 License.

// * Ant Real Time Operating System is distributed in the hope that it will 
// * be useful,but WITHOUT ANY WARRANTY; without even the implied warranty 
// * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
// * Apache-2.0 License License for more details.

// * You should have received a copy of the Apache-2.0 License.Ant Real Time
// * Operating System. If not, see <http://www.apache.org/licenses/>.
//**/
///*------------------------------------------------------------------------
//|                                INCLUDES                                |
//------------------------------------------------------------------------*/

//#include "os_core.h"
//#include "os_port.h"
//#include "heap_os.h"


//#include "os_object.h"


///*------------------------------------------------------------------------
//|                                  DATA                                  |
//------------------------------------------------------------------------*/

///**
//  * @name    G_OS_Stack
//  * @brief   RTOS kernel stack.
//***/
//OS_Stack_t G_OS_Stack[128];

///**
//  * @name    G_StkBytes
//  * @brief   RTOS stack length (unit:bytes).
//***/
//uint8_t xdata G_StkBytes;

///**
//  * @name    G_pXRAMStk
//  * @brief   RTOS access external RAM pointer.
//***/
//uint8_t xdata * data G_pXRAMStk; 

///**
//  * @name    G_pRAMStk
//  * @brief   RTOS accesses the internal RAM pointer..
//***/
//uint8_t idata * data G_pRAMStk; 

///**
//  * @name    OS_Idle_Task_Function
//  * @brief   RTOS idle task handle function.
//***/
//OS_Idle_Task_t OS_Idle_Task_Function = NULL;

///**
//  * @name    G_Idle_Stack
//  * @brief   RTOS idle task stack.
//***/
//Task_Stack_t G_Idle_Stack[20];

///**
//  * @name    G_TCB_RunNode
//  * @brief   RTOS TCB runing node.
//***/
//extern OS_TCB_t xdata * G_TCB_RunNode;

///**
//  * @name    G_TCB_RdyList
//  * @brief   RTOS TCB ready list.
//***/
//extern TCB_RdyList_t G_TCB_RdyList;

///**
// * @brief   阻塞任务链表。
// * @details List os blocked tasks.
//**/
//extern TCB_BlkList_t G_TCB_BlkList;

///**
// * @brief   休眠任务链表。
// * @details List os slpeeing tasks.
//**/
//extern TCB_SlpList_t G_TCB_SlpList;

///*------------------------------------------------------------------------
//|                              API FUNCTIONS                             |
//------------------------------------------------------------------------*/

///**
//  * @name    OS_Idle_Task
//  * @brief   RTOS idle task.
//  * @param   None.
//  * @retval  None.
//***/
//static void OS_Idle_Task(void);


///**
// * @brief   MCU TIMER0 Interrupt request service function
// * @param   None
// * @return  None
//**/
////void TIMER0_ISRQ_Handler(void) interrupt 1
////{
////	
////	os_uint8_t slpCtr = 0;   /*!< 休眠任务计数变量。Count variable of sleeping tasks. */
////	os_uint8_t slpEndCtr = 0; /*!< 休眠任务结束的计数变量。Count variable for the end of the sleeping tasks. */
////	os_uint8_t slpEndFlag = 0; /*!< 休眠任务结束的标志位变量。The flag variable for the end of the dormant task. */
////	
////	
////	
////	for(slpCtr = 0;slpCtr < G_TCB_SlpList.SlpNum;slpCtr++)
////	{
////		/** 如果有任务休眠时间结束，就将其加入就绪列表，同时统计结束休眠任务的数量。 */
////		if(--G_TCB_SlpList.SlpPtr[slpCtr] -> TaskSlp == 0)
////		{
////			G_TCB_SlpList.SlpPtr[slpCtr] -> TaskState = OSTask_Ready;
////			G_TCB_RdyList.RdyPtr[G_TCB_RdyList.RdyNum++] = G_TCB_SlpList.SlpPtr[slpCtr];
////			G_TCB_SlpList.SlpPtr[slpCtr] = NULL;
////			slpEndCtr++;
////		}
////	}
////	
////	if(slpEndCtr)
////	{	
////		slpEndCtr = 0;
////		for(slpCtr = 0; slpCtr < G_TCB_SlpList.SlpNum; slpCtr++)
////		{
////			if(G_TCB_SlpList.SlpPtr[slpCtr] == NULL)
////			{
////				G_TCB_SlpList.SlpPtr[slpCtr] = G_TCB_SlpList.SlpPtr[--G_TCB_SlpList.SlpNum];
////				G_TCB_SlpList.SlpPtr[G_TCB_SlpList.SlpNum] = NULL;
////			}
////		}
////		
////	}
////	
////}

///**
//  * @name    AntOS_Init
//  * @brief   Initailize RTOS.
//  * @param   None
//  * @retval  [OS_OK] Ant RTOS initailized successfully. 
//  * @retval  [OS_NOK] Ant RTOS initailized failed. 
//***/
//os_uint8_t AntOS_Init(void)
//{
//	if(OS_Object_Container_Init() != OS_OK) return OS_NOK;
//	//if(OS_Task_Create(OS_Idle_Task,0,G_Idle_Stack,20) != OS_OK) return OS_NOK;
//	return OS_OK;
//}

///**
//  * @name    OS_Start
//  * @brief   Start scheduling RTOS.
//  * @param   None
//  * @retval  None
//***/
//void OS_Start(void)
//{	
//	os_uint8_t num = 0;
//	os_uint8_t maxPrio = 0,maxPrioCtr=0;
//	
//	for(num=0;num < G_TCB_RdyList.RdyNum;num++)
//	{
//		
//		if (G_TCB_RdyList.RdyPtr[num] -> TaskPrio > maxPrio)
//		{
//			maxPrio = G_TCB_RdyList.RdyPtr[num] -> TaskPrio;
//			maxPrioCtr = num;
//		}
//	}
//	
//	G_TCB_RunNode = G_TCB_RdyList.RdyPtr[maxPrioCtr];
//	
//	G_TCB_RunNode -> TaskState = OSTask_Runing;
//	
//	G_TCB_RdyList.RdyPtr[maxPrioCtr] = G_TCB_RdyList.RdyPtr[--G_TCB_RdyList.RdyNum];
//	G_TCB_RdyList.RdyPtr[G_TCB_RdyList.RdyNum] = NULL;
//	

//	G_pXRAMStk = G_TCB_RunNode -> StkAddr;
//	G_pRAMStk = G_OS_Stack;
//	G_StkBytes = G_pXRAMStk[0];
//	
//	while(G_StkBytes--)                                    
//	{                                                      
//		*(++G_pRAMStk) = *(++G_pXRAMStk);  		                            
//	}
//	
//    SP = (uint8_t)(G_pRAMStk - 13);
//}

///**
//  * @name    OS_Idle_Task
//  * @brief   RTOS idle task.
//  * @param   None.
//  * @retval  None.
//***/
//void OS_Idle_Task(void)
//{
//	os_uint8_t num = 0;
//	os_uint8_t maxPrio = 0,maxPrioCtr = 0;
//	OS_TCB_t *runNode;
//	for(;;)
//	{

//		/* If user will be use idle task handle function, run it.*/
//		if(OS_Idle_Task_Function) OS_Idle_Task_Function();

//		/* If task priority pf runing TCB node smaller than next node in the ready list,
//		 * Runing task state changed "OSTask_Ready".
//		 * RTOS exits the critical area of the system.
//   		 * Switch context at the same time. */
//		
//		for(num=0;num < G_TCB_RdyList.RdyNum;num++)
//		{
//			if (G_TCB_RdyList.RdyPtr[num] -> TaskPrio > maxPrio)
//			{
//				maxPrio = G_TCB_RdyList.RdyPtr[num] -> TaskPrio;
//				maxPrioCtr = num;
//			}
//		}
//		
//		if ((G_TCB_RunNode -> TaskPrio ) < G_TCB_RdyList.RdyPtr[maxPrioCtr] -> TaskPrio && G_TCB_RdyList.RdyNum != 0)
//		{
//			/* RTOS enters the critical area of the system. */
//			
//			OS_ENTER_CRITICAL();
//			
//			runNode = G_TCB_RdyList.RdyPtr[0];
//			G_TCB_RdyList.RdyPtr[0] = G_TCB_RdyList.RdyPtr[maxPrioCtr];
//			G_TCB_RdyList.RdyPtr[maxPrioCtr] = runNode;
//			
//			G_TCB_RunNode -> TaskState = OSTask_Ready;
//			
//			OS_Context_Schedule();
//			
//		}

//	}
//}




///*------------------------------------------------------------------------
//|                    END OF FLIE.  (C) COPYRIGHT zeweni                  |
//------------------------------------------------------------------------*/